package cn.cdyx.ydhl.controller;

import cn.cdyx.common.annotation.NotNeedInterceptor;
import cn.cdyx.common.annotation.SysLog;
import cn.cdyx.common.exception.SystemException;
import cn.cdyx.common.pojo.Code;
import cn.cdyx.common.pojo.HXYTEST;
import cn.cdyx.common.pojo.TBSYSTABLES;
import cn.cdyx.common.cache.TbsysTablesCache;
import cn.cdyx.common.utils.TableNameUtil;
import cn.cdyx.common.utils.YXParamUtil;
import cn.cdyx.common.utils.YXSysNumberUtil;
import cn.cdyx.ydhl.service.HXYTESTServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

@Controller
@RequestMapping("hxy")
public class HXYTESTController {
    @Autowired
    private HXYTESTServer hxytestServer;
    @Autowired
    private TbsysTablesCache tbsystablesService;

    @RequestMapping("{gh}")
    @ResponseBody
    public List<TBSYSTABLES> save(@PathVariable("gh") long gh){
        return tbsystablesService.tbsystables;
    }
    @RequestMapping("hxy/{gh}")
    @ResponseBody
    public String save1(@PathVariable("gh") long gh){
        HXYTEST hxytest = new HXYTEST();
        hxytest.setIbm(1);
        hxytest.setCmc("haha");
        return hxytestServer.saveHXY(hxytest);
    }

    @RequestMapping("hxy1/{tablename}")
    @ResponseBody
    public Object test(@PathVariable("tablename") String tablename) throws ParseException {
        return TableNameUtil.getYearTableNames("TBFYMX",
                new SimpleDateFormat("yyyy-MM-dd").parse("2020-01-01"),
                new SimpleDateFormat("yyyy-MM-dd").parse("2020-08-01"));
    }

    @RequestMapping("hxy2/{tbuserparam}")
    @ResponseBody
    public Object testtbuserparam(@PathVariable("tbuserparam") String tablename) throws ParseException {
        return YXParamUtil.getUserParamObj("KSYSDYF");
    }
    @RequestMapping("hxy3/{tbyxxtcsi}")
    @ResponseBody
    public Object testtbyxxtcsi(@PathVariable("tbyxxtcsi") String tablename) throws ParseException {
        return YXParamUtil.getUserParam("KYFZYPYF","");
    }


    @RequestMapping("hxy4/{sz}")
    @ResponseBody
    @SysLog(desc="测试接口")
    public Object exception(@PathVariable("sz") Integer sz) {
        if(sz==1){
            throw new SystemException(Code.SELECT_ERR,"不能为1",null);
        }
        String cyzzxjlph = YXSysNumberUtil.getSysNumber("0000", 1, 13);
        return cyzzxjlph;
    }

    @RequestMapping("hxy5/{sz}")
    @ResponseBody
    @NotNeedInterceptor
    public Object exception1(@PathVariable("sz") Integer sz) {
        int i = 1/0;
        return sz;
    }

    @RequestMapping("hxy6/{sz}")
    @ResponseBody
    @NotNeedInterceptor
    public Object exception2(@PathVariable("sz") Integer sz) {

        return sz;
    }
}
